package cn.edu.scau.cmi.wuzhenxin.composite.consistent;

import java.util.ArrayList;


public class ConsistentComposite extends ConsistentComponent{
	private ArrayList<ConsistentComponent> consistentList;
	private String name = "";
	private ConsistentComponent parent = null;
	public ConsistentComposite(String name) {//构造方法，初始化文件夹队列
		this.name = name;
		consistentList = new ArrayList<ConsistentComponent>();
	}
	
	@Override
	public String say() {
		// TODO Auto-generated method stub
		String saying = "";
		saying  += (number++)+"组织：" +this.name +"\n";
		for(int i = 0 ; i < consistentList.size();i++) {
			ConsistentComponent component = consistentList.get(i);
			saying += " "+component.say();
		}
		return saying;
	}

	@Override
	public void add(ConsistentComponent organization) {
		// TODO Auto-generated method stub
		consistentList.add(organization);
	}

	@Override
	public void remove(ConsistentComponent organization) {
		// TODO Auto-generated method stub
		consistentList.remove(organization);
	}

	@Override
	public ArrayList<ConsistentComponent> getChildren() {
		// TODO Auto-generated method stub
		return consistentList;
	}
	
	public void setParent(ConsistentComponent parent) {//设置父节点
		if(parent instanceof ConsistentComposite) {
			this.parent = parent;
			((ConsistentComposite) this.parent).add(this);
		}	
	}
	
	public ConsistentComponent getParent() {//得到父节点
		if(this.parent != null)
			return this.parent;
		
			return null;
	}
	
}
